define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'refund/verify/index',
                    edit_url: 'refund/verify/verify_one',
                    verify_url: 'refund/verify/verify_batch',
                    table: 'refund',
                }
            });

            var table = $("#table");
          var toolbar = $('#toolbar');

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'expenses', title: __('Expenses_id'),formatter:function(value){
                          return value.community.name + ' - ' + value.house.name + ' - ' + value.project.name;
                          }},
                        {field: 'amount', title: __('Amount')},
                        {field: 'reason', title: __('Reason')},
                        {field: 'verify', title: __('Verify'),formatter: function(value){
                            var statuses = ['WaitVerify','PassVerify','RefuseVerify'];
                            return Table.api.formatter.status(statuses[value]);
                          }},
                        {field: 'create_time', title: __('Create_time'), formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);

          toolbar.on('click','.btn-verify',function(e){
            e.preventDefault()
            var ids = Table.api.selectedids(table)
            var options = table.bootstrapTable('getOptions');
            Fast.api.open(options.extend.verify_url + (options.extend.verify_url.match(/(\?|&)+/) ? "&ids=" : "/ids/") + ids, __('Verify'), $(this).data() || {});
          })
        },

      verify_one: function () {
        Controller.api.bindevent();
      },
      verify_batch:function(){
        Controller.api.bindevent();
      },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});